package com.zack.gank.gankandroid.find;

import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ProgressBar;

import com.bumptech.glide.Glide;
import com.zack.gank.gankandroid.MyApplication;
import com.zack.gank.gankandroid.gankandroid.R;
import com.zack.gank.gankandroid.main.find.bean.Gank;
import com.zack.gank.gankandroid.view.NestedScrollWebView;
import com.zack.gank.gankandroid.view.ProgressWebChromeClient;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Android on 2017/7/20.
 */
public class FindDetailActivity extends AppCompatActivity {


    NestedScrollWebView webDetail;
    Toolbar toolbar;
    ImageView ivBookImage;
    CollapsingToolbarLayout collapsing_toolbar_layout;
    Gank gank;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.activity_find_detail);

        gank= (Gank) getIntent().getSerializableExtra("gank");
        webDetail = (NestedScrollWebView) findViewById(R.id.web_detail);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        ivBookImage = (ImageView) findViewById(R.id.iv_book_image);

        if(MyApplication.getContext().getComonImageUrl().size()>0){
            Random random=new Random();
            int position= random.nextInt()/MyApplication.getContext().getComonImageUrl().size();
            if(position<0){
                position=1;
            }
            if(position>=MyApplication.getContext().getComonImageUrl().size()){
                position=MyApplication.getContext().getComonImageUrl().size()-1;
            }
            Glide.with(this).load(MyApplication.getContext().getComonImageUrl().get(position).url).into(ivBookImage);
        }
        collapsing_toolbar_layout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar_layout);
        collapsing_toolbar_layout.setTitle(gank.who);
        WebSettings webSettings=webDetail.getSettings();
        webSettings.setJavaScriptEnabled(true);
       /* ProgressBar progressBar=new ProgressBar(this);
        progressBar.setMax(100);*/
//        webDetail.setWebChromeClient(new ProgressWebChromeClient(progressBar));
        webDetail.loadUrl(gank.url);
        webDetail.setWebViewClient(new WebViewClient(){
            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
                return super.shouldInterceptRequest(view, request);
            }
        });



    }
}
